#include "Pch.h"
#include "OpenGLBuffer.h"
#include <glad\glad.h>
namespace Engine 
{
	// ===================
	// OpenGL VertexBuffer
	GLVertexBuffer::~GLVertexBuffer()
	{
		glDeleteBuffers(1, &m_Handle);
	}

	void GLVertexBuffer::Bind() const
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_Handle);
	}

	void GLVertexBuffer::UnBind() const
	{
		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}

	GLVertexBuffer::GLVertexBuffer(float* vertics, UINT32 size)
	{
		glCreateBuffers(1, &m_Handle);
		glBindBuffer(GL_ARRAY_BUFFER, m_Handle);
		glBufferData(GL_ARRAY_BUFFER, size, vertics, GL_STATIC_DRAW);
	}
	// OpenGL VertexBuffer
	// ===================



	//  ==================
	//  OpenGL IndexBuffer
	GLIndexBuffer::~GLIndexBuffer()
	{
		glDeleteBuffers(1, &m_Handle);
	}

	void GLIndexBuffer::Bind() const
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_Handle);
	}

	void GLIndexBuffer::UnBind() const
	{
		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}

	GLIndexBuffer::GLIndexBuffer(UINT32* indices, UINT32 count)
	{
		m_Count = count;
		glCreateBuffers(1, &m_Handle);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Handle);
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(uint32_t), indices, GL_STATIC_DRAW);
	}

	//  OpenGL IndexBuffer
	//  ==================
}